pub fn odd_fibnacci_sum(threshold: u32) -> u32 {
    Fibnacci::new()
        .take_while(|&n| n <= threshold)
        .filter(|&n| n % 2 == 1)
        .sum()
}

struct Fibnacci {
    previous: u32,
    current: u32,
}

impl Fibnacci {
    pub fn new() -> Self {
        Fibnacci {
            previous: 0,
            current: 0,
        }
    }
}

impl Iterator for Fibnacci {
    type Item = u32;

    fn next(&mut self) -> Option<Self::Item> {
        Some(if self.current > 0 {
            let current = self.previous + self.current;
            self.previous = self.current;
            self.current = current;
            current
        } else {
            self.current = 1;
            1
        })
    }
}
